//
//  YFUserDefaults.m
//  SquashSpark
//
//  Created by Coollang on 2017/11/10.
//  Copyright © 2017年 Coollang-YF. All rights reserved.
//

#import "YFUserDefaults.h"

@implementation YFUserDefaults

+ (void)saveAppVersion:(NSString *)version
{
    [[NSUserDefaults standardUserDefaults] setObject:version forKey:@"version"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (NSString *)storeAppVersion
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"version"];
}
+ (void)saveLastLoginAccountID:(NSString *)accountID
{
    [[NSUserDefaults standardUserDefaults] setObject:accountID forKey:@"lastLoginID"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (NSString *)lastLoginID
{
    return [[NSUserDefaults standardUserDefaults] stringForKey:@"lastLoginID"];
}

+ (BOOL)shouldAutoLogin {
    BOOL autoLogin = [[NSUserDefaults standardUserDefaults] boolForKey:@"hasLogin"];
    return autoLogin;
}

+ (void)setAutoLogin:(BOOL)hasLogin
{
    [[NSUserDefaults standardUserDefaults] setBool:hasLogin forKey:@"hasLogin"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
+ (NSArray *)zonesArray{
    return [[NSUserDefaults standardUserDefaults] valueForKey:@"zonesArray"];
}

+ (void)setZonesArray:(NSArray<NSString *> *)array {
    if (![YFUserDefaults zonesArray] || ![YFUserDefaults zonesArray].count) {
        [[NSUserDefaults standardUserDefaults] setObject:array forKey:@"zonesArray"];
    }
}

#pragma mark - 个人中心通用设置
+ (void)setGeneralMetricSystemUnit:(BOOL)isMetric {
    [[NSUserDefaults standardUserDefaults] setBool:isMetric forKey:[NSString stringWithFormat:@"GeneralSystem%@",[User getLastUser].userID]];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
+ (BOOL)generalMetricSystemUnit {
    return [[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:@"GeneralSystem%@",[User getLastUser].userID]];
}

/**
 是否需要刷新朋友圈
 @param                 isNeed      YES:需要 NO:不需要
 */
+ (void)saveMomentRefreshState:(BOOL)isNeed{
    [[NSUserDefaults standardUserDefaults] setBool:isNeed forKey:@"isNeedRefreshMoment"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
/**
 是否需要刷新朋友圈数据
 */
+ (BOOL)isNeedRefreshMoment{
    BOOL isNeed = [[NSUserDefaults standardUserDefaults] boolForKey:@"isNeedRefreshMoment"];
    if (isNeed) {
        [self saveMomentRefreshState:NO];
    }
    return isNeed;
}

//  是否需要刷新CLUB-ME界面布局
+ (void)saveClubMeRefreshState:(BOOL)isNeed{
    [[NSUserDefaults standardUserDefaults] setBool:isNeed forKey:@"isNeedRefreshClubMe"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
+ (BOOL)isNeedRefreshClubMe{
    BOOL isNeed = [[NSUserDefaults standardUserDefaults] boolForKey:@"isNeedRefreshClubMe"];
    if (isNeed) {
        [self saveClubMeRefreshState:NO];
    }
    return isNeed;
}

// 同步主页数据最新更新的时间戳
+ (void)saveLastUpdateTime:(NSInteger)lastUpdateTime {
    [[NSUserDefaults standardUserDefaults] setInteger:lastUpdateTime forKey:[NSString stringWithFormat:@"%@lastUpdateTime",[User getLastUser].userID]];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
+ (NSInteger)lastUpdateTime {
    return [[NSUserDefaults standardUserDefaults] integerForKey:[NSString stringWithFormat:@"%@lastUpdateTime",[User getLastUser].userID]];
}

/**
 是否需要展示引导图
 @return                是否需要引导
 */
+ (BOOL)isNeedGuideView {
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    BOOL isShowed = [[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:@"-%@-",app_Version]];
    if (isShowed == NO) {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:[NSString stringWithFormat:@"-%@-",app_Version]];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    return !isShowed;
}

//是否需要切换到ME
+ (void)saveClubOnMEState:(BOOL)isNeed{
    [[NSUserDefaults standardUserDefaults] setBool:isNeed forKey:@"-ClubIsOnMe-"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
+ (BOOL)isShowMe{
    return [[NSUserDefaults standardUserDefaults] boolForKey:@"-ClubIsOnMe-"];
}

@end
